package com.baidumap.administrator.happystudy.adapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ab.util.AbStrUtil;
import com.baidumap.administrator.happystudy.R;
import com.baidumap.administrator.happystudy.base.Constant;
import com.baidumap.administrator.happystudy.model.QuizList;
import com.baidumap.administrator.happystudy.utils.GlideUtil;

import java.util.List;

/**
 * Created by C on 2017/3/25.
 * 老师解题适配器
 */
public class SolveProblemAdapter extends BaseAdapter {
    private Context mContext;

    private List<QuizList.DataBean> dataBeenList;
    private LayoutInflater inflater;

    public SolveProblemAdapter(Context context, List<QuizList.DataBean> dataBeenList) {
        mContext = context;
        this.dataBeenList = dataBeenList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return dataBeenList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_solve_problem, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.img = (ImageView) convertView.findViewById(R.id.img);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tv_school = (TextView) convertView.findViewById(R.id.tv_school);
            viewHolder.tv_subject = (TextView) convertView.findViewById(R.id.tv_subject);
            viewHolder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_title.setText(dataBeenList.get(position).getTitle());
        viewHolder.tv_time.setText(AbStrUtil.stampToDate(dataBeenList.get(position).getCreated_at()));
        viewHolder.tv_school.setText(dataBeenList.get(position).getSchool() + " " + dataBeenList.get(position).getSection() + " " + dataBeenList.get(position).getGrade());
        viewHolder.tv_content.setText(Html.fromHtml(dataBeenList.get(position).getContent()));
        viewHolder.tv_subject.setText(dataBeenList.get(position).getStudent_name());

        GlideUtil.displayImg(mContext, Constant.DOMAIN + dataBeenList.get(position).getImages().get(0), viewHolder.img);
        return convertView;
    }

    class ViewHolder {
        private ImageView img;
        private TextView tv_title;
        private TextView tv_subject;
        private TextView tv_content;
        private TextView tv_school;
        private TextView tv_time;
    }
}
